@using BlazorApp.Pages.Common.Html
@using BlazorApp.Pages.Common.Html.HTable
@using BlazorApp.Pages.Common.Metadata
@using BlazorApp.Pages.Event
@using BlazorApp.Pages.Pod.Affinity
@using BlazorApp.Pages.Pod.Volume
@using k8s.Models
@using Mapster
@inherits BlazorApp.Pages.Common.DrawerPageBase<k8s.Models.V1PersistentVolume>
@if (PersistentVolume != null)
{
    <PersistentVolumeAction Item="PersistentVolume" MenuMode="MenuMode.Horizontal"></PersistentVolumeAction>
    <Divider Orientation="left" Style="font-weight:bold">@L["Metadata"]</Divider>
    <MetadataView Item="PersistentVolume.Metadata" ExplainFieldPrefix="persistentVolume"></MetadataView>
    <Divider Orientation="left" Style="font-weight:bold">@L["Spec"]</Divider>
    <HTable Bordered Column="1">
        <PropertySimpleView Title=@L["StorageClassName"] Item="@PersistentVolume.Spec.StorageClassName"
                            ExplainField="persistentVolume.spec.storageClassName">
        </PropertySimpleView>
        <PropertyListView Title=@L["AccessModes"] Items="@PersistentVolume.Spec.AccessModes"
                          ExplainField="persistentVolume.spec.accessModes" T="string">
        </PropertyListView>
        <PropertyMapView Title=@L["Capacity"] Items="@PersistentVolume.Spec.Capacity"
                         ExplainField="persistentVolume.spec.capacity" T="ResourceQuantity">
        </PropertyMapView>
        @if (PersistentVolume.Spec.ClaimRef != null)
        {
            <HTableColumn Title=@L["ScaleTarget"]>
                <RefView FullView="true" Ref="@PersistentVolume.Spec.ClaimRef"></RefView>
            </HTableColumn>
        }

        <PropertyListView Title=@L["MountOptions"] Items="@PersistentVolume.Spec.MountOptions"
                          ExplainField="persistentVolume.spec.mountOptions" T="string">
        </PropertyListView>
        <PropertyOptionView Title=@L["PvReclaimPolicy"] Item="@PersistentVolume.Spec.PersistentVolumeReclaimPolicy"
                            ExplainField="persistentVolume.spec.persistentVolumeReclaimPolicy"
                            Options='@(new[] { "Delete", "Recycle", "Retain" })'>
        </PropertyOptionView>
        <PropertyOptionView Title=@L["VolumeMode"] Item="@PersistentVolume.Spec.VolumeMode"
                            ExplainField="persistentVolume.spec.volumeMode"
                            Options='@(new[] { "Block", "Filesystem" })'>
        </PropertyOptionView>
        @if (PersistentVolume.Spec.NodeAffinity != null)
        {
            <HTableColumn Title=@L["NodeAffinity"]>
                @{
                    var required = PersistentVolume.Spec.NodeAffinity.Required;
                    @if (required != null)
                    {
                        @foreach (var term in required.NodeSelectorTerms)
                        {
                            <NodeSelectorRequirementView
                                MatchExpressions="@term.MatchFields" Type="Required"
                                SelectType="Field"
                                ExplainField="persistentVolume.spec.nodeAffinity.required.nodeSelectorTerms.matchFields">
                            </NodeSelectorRequirementView>
                            <NodeSelectorRequirementView
                                MatchExpressions="@term.MatchExpressions" Type="Required"
                                SelectType="Label"
                                ExplainField="persistentVolume.spec.nodeAffinity.required.nodeSelectorTerms.matchExpressions">
                            </NodeSelectorRequirementView>
                        }
                    }
                }
            </HTableColumn>
        }


        <CsiSourceView FieldPrefix="persistentVolume.spec" Csi="@(PersistentVolume.Spec.Csi.Adapt<V1CSIVolumeSource>())"></CsiSourceView>
        <FcSourceView FieldPrefix="persistentVolume.spec" Fc="@PersistentVolume.Spec.Fc"></FcSourceView>
        <HostPathSourceView FieldPrefix="persistentVolume.spec" HostPath="@PersistentVolume.Spec.HostPath"></HostPathSourceView>
        <IscsiSourceView FieldPrefix="persistentVolume.spec" Iscsi="@(PersistentVolume.Spec.Iscsi.Adapt<V1ISCSIVolumeSource>())"></IscsiSourceView>
        <NfsSourceView Nfs="@PersistentVolume.Spec.Nfs" FieldPrefix="persistentVolume.spec"></NfsSourceView>
        <LocalSourceView Local="@PersistentVolume.Spec.Local" FieldPrefix="persistentVolume.spec"></LocalSourceView>

        @* TODO MORE PV  *@
        <PropertySimpleView Title=@L["Rbd"] Item="@PersistentVolume.Spec.Rbd" ExplainField="persistentVolume.spec.rbd"
                            ShowInJson="true">
        </PropertySimpleView>
        <PropertySimpleView Title=@L["Glusterfs"] Item="@PersistentVolume.Spec.Glusterfs"
                            ExplainField="persistentVolume.spec.glusterfs" ShowInJson="true">
        </PropertySimpleView>
        <PropertySimpleView Title=@L["Cephfs"] Item="@PersistentVolume.Spec.Cephfs"
                            ExplainField="persistentVolume.spec.cephfs" ShowInJson="true">
        </PropertySimpleView>
        <PropertySimpleView Title=@L["Cinder"] Item="@PersistentVolume.Spec.Cinder"
                            ExplainField="persistentVolume.spec.cinder" ShowInJson="true">
        </PropertySimpleView>

    </HTable>
    <Divider Orientation="left" Style="font-weight:bold">@L["Status"]</Divider>
    <HTable Bordered Column="1">
        <PropertySimpleView Title=@L["LastPhaseTransitionTime"] Item="@PersistentVolume.Status.LastPhaseTransitionTime"
                            ExplainField="persistentVolume.status.lastPhaseTransitionTime">
        </PropertySimpleView>
        <PropertySimpleView Title=@L["Message"] Item="@PersistentVolume.Status.Message"
                            ExplainField="persistentVolume.status.message">
        </PropertySimpleView>
        <PropertySimpleView Title=@L["Phase"] Item="@PersistentVolume.Status.Phase" ExplainField="persistentVolume.status.phase"></PropertySimpleView>
        <PropertySimpleView Title=@L["Reason"] Item="@PersistentVolume.Status.Reason"
                            ExplainField="persistentVolume.status.reason">
        </PropertySimpleView>
    </HTable>
    <MiniEventListView Uid="@PersistentVolume.Metadata.Uid"></MiniEventListView>
}
